package com.abel.util;

import java.util.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Tester {

	public Tester() {
		this.testDate("");
	}
	
	public void testRegex(String str) {
		if (str.matches("[1-9|,]*")){
			System.out.println("matches");
		}
	}
	
	public void testDate(String str) {
//		if (str.matches("\\d{2}[-|/]\\d{2}[-|/]\\d{4}")){
//			System.out.println("matches" + str);
//		}
		if (str.matches("(0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])/((19|20)\\d\\d)")) {
			System.out.println("matches" + str);
		}
	}
	
	public void testDateFormat(String dateStr) {
		SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
		Calendar cal = Calendar.getInstance();
		try {
			cal.setTime(sdf.parse(dateStr));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Date date = new Date(cal.getTimeInMillis());
		
	}
	
	
	public void testFormattingDate(Date date) {
		
		if (date != null) {
			
			DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
			try {
				String str = dateFormat.format(date);
				Date dt = dateFormat.parse(str);;
				date = dt;
				
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		
	}
	
	
	public void testDateDateFormat(String date) {
		
		if (date.matches("\\d{2}[-|/]\\d{4}")) {
			System.out.println(date + " matches");
		}
		else {
			System.out.println(date + " does not match");
		}
	}
	
	
	
	public static void main(String[] args) {
		Tester tester = new Tester();
//		tester.testRegex("2,3");
//		tester.testRegex("ab");
//		tester.testRegex("a,b");
//		tester.testRegex("2");
//		tester.testRegex(",2,3");
//		tester.testRegex("234234");
		tester.testDate("1/1/01");
		tester.testDate("01/01/01");
		tester.testDate("1/1/2001");
		tester.testDate("01/01/2001");
		tester.testDate("1-1-01");
		tester.testDate("01-01-01");
		tester.testDate("01-01-2001");
		tester.testDate("24/24/2002");
		tester.testDate("204/24/2002");
		tester.testDate("13/2/2002");
//		tester.testDateFormat("01-01-2001");
//		tester.testFormattingDate(new Date());
//		tester.testDateDateFormat("02/2004");
//		tester.testDateDateFormat("02-2004");
	}
	
	
	
	
}
